

set scheme s1mono

****************************
***   Background plots   ***
****************************


gen school5 = 0 if school != .
replace school5 = 1 if school >=5 & school != .


*** 2005-2008

gen sat_dem = satisfaction_democracy
recode sat_dem (1/2=1)
label var sat_dem "Satisfaction with Senegal's Democracy"

gen how_dem = how_democratic
recode how_dem (1/2=1)
label var how_dem "Believe That Senegal is a Functioning Democracy"


global vars sat_dem how_dem

foreach var of varlist $vars {
	egen mean_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997, by(year)
	egen mean1_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997 & school5 == 0, by(year)
	egen mean2_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997 & school5 == 1, by(year)

}

foreach var of varlist $vars {
		local vlab : variable label `var'
		twoway ///
		(line mean_`var' year, lcolor(gs0)) ///
		(line mean1_`var' year, lcolor(gs12) lpattern(dash)) ///
		(line mean2_`var' year, lcolor(gs0) lpattern(dash)), ///
		legend(order(1 2 3) label(1 "Aggregate") label(2 " Primary or lower") label(3 "Some secondary")) ///
		title("`vlab'") ytitle("") xtitle("Survey Year") xlabel(2002 2005 2008 2013 2014)
		quietly: graph export "plots/`vlab'.pdf", replace
}




gen trust_ec = trust_EC
recode trust_EC (1/3=1)

gen elections = elections_free_fair
recode elections (1=0) (2/4=1)

global vars trust_ec elections
label var trust_ec "Trust Electoral Commission"
label var elections "Elections are Free and Fair"

foreach var of varlist $vars {
	egen mean_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997, by(year)
	egen mean1_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997 & school5 == 0, by(year)
	egen mean2_`var' = mean(`var') if birthyear_control >= 1970 & birthyear_control <= 1997 & school5 == 1, by(year)
}


foreach var of varlist $vars {
		local vlab : variable label `var'
		twoway ///
		(line mean_`var' year, lcolor(gs0)) ///
		(line mean1_`var' year, lcolor(gs12) lpattern(dash)) ///
		(line mean2_`var' year, lcolor(gs0) lpattern(dash)), ///
		legend(order(1 2 3) label(1 "Aggregate") label(2 " Primary or lower") label(3 "Some secondary")) ///
		title("`vlab'") ytitle("") xtitle("Survey Year") xlabel(2002 2005 2008 2013 2014)
		quietly: graph export "plots/`vlab'.pdf", replace
}



***********************************************
***   Diff in diff plots for Appendix A.4   ***
***********************************************

bys birthyear: gen cohort_weight = _N

foreach var of varlist school4 indiv2 indiv3 indiv4 {
	
	local vlab : variable label `var'
	
	bys birthyear: egen m1_`var' =mean(`var') if treat2_10_inc <= med_treat2_10_inc & treat2_10_inc != .
	bys birthyear: egen m2_`var' =mean(`var') if treat2_10_inc > med_treat2_10_inc & treat2_10_inc != .
	
	twoway (scatter m1_`var' birthyear if birthyear >= 1970 & birthyear <= 1997 [w=cohort_weight], color(gs9) msize(vsmall)) ///
  (scatter m2_`var' birthyear if birthyear >= 1970 & birthyear <= 1997 [w=cohort_weight], color(black) msize(vsmall)) ///
		(lpoly m1_`var' birthyear if birthyear >= 1970 & birthyear < 1986, bwidth(2) lcolor(gs9) clwidth(medthick)) ///
		(lpoly m2_`var' birthyear if birthyear >= 1970 & birthyear < 1986, bwidth(2) lcolor(black) clwidth(medthick)) /// 
		(lpoly m1_`var' birthyear if birthyear >= 1986 & birthyear <= 1997, bwidth(2) lcolor(gs9) clwidth(medthick)) ///
		(lpoly m2_`var' birthyear if birthyear >= 1986 & birthyear <= 1997, bwidth(2) lcolor(black) clwidth(medthick)), ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xtitle("Year of birth") legend(nobox region(fcolor(white) margin(zero) lcolor(white)) ///
		lab(3 "Below-median intensity") lab(6 "Above-median intensity") order(3 6)) ylab(, nogrid) ytitle("Proportion") title("`vlab'") xline(1986, lcolor(black) lpattern(dash)) xlabel(1970(5)1995)
	drop m1* m2*
	local y `"`y' "`var'""' 
	quietly: graph export "plots/`vlab'.pdf", replace
	
}


label var economic_index "Economic index"
label var information "Information index"
label var participation_index "Participation Index"
label var dem_checks_on_pres "Checks on President"

foreach var of varlist economic_index information participation_index dem_checks_on_pres {
	
	local vlab : variable label `var'
	
	bys birthyear: egen m1_`var' =mean(`var') if treat2_10_inc <= med_treat2_10_inc & treat2_10_inc != .
	bys birthyear: egen m2_`var' =mean(`var') if treat2_10_inc > med_treat2_10_inc & treat2_10_inc != .
	
	twoway (scatter m1_`var' birthyear if birthyear >= 1970 & birthyear <= 1997 [w=cohort_weight], color(gs9) msize(vsmall)) ///
  (scatter m2_`var' birthyear if birthyear >= 1970 & birthyear <= 1997 [w=cohort_weight], color(black) msize(vsmall)) ///
		(lpoly m1_`var' birthyear if birthyear >= 1970 & birthyear < 1986, bwidth(2) lcolor(gs9) clwidth(medthick)) ///
		(lpoly m2_`var' birthyear if birthyear >= 1970 & birthyear < 1986, bwidth(2) lcolor(black) clwidth(medthick)) /// 
		(lpoly m1_`var' birthyear if birthyear >= 1986 & birthyear <= 1997, bwidth(2) lcolor(gs9) clwidth(medthick)) ///
		(lpoly m2_`var' birthyear if birthyear >= 1986 & birthyear <= 1997, bwidth(2) lcolor(black) clwidth(medthick)), ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xtitle("Year of birth") legend(nobox region(fcolor(white) margin(zero) lcolor(white)) ///
		lab(3 "Below-median intensity") lab(6 "Above-median intensity") order(3 6)) ylab(, nogrid) ytitle("Scale") title("`vlab'") xline(1986, lcolor(black) lpattern(dash)) xlabel(1970(5)1995)
	drop m1* m2*
	local y `"`y' "`var'""' 
	quietly: graph export "plots/`vlab'.pdf", replace
	
}




